package com.zhaos.cluster;

import com.zhaosc.invoke.Invocation;
import com.zhaosc.invoke.Invoke;

public class FailoverClusterInvoke implements Cluster {

	@Override
	public String invoke(Invocation invocation) throws Exception {
		
		String retries=invocation.getReference().getRetries();
		Integer retry=Integer.parseInt(retries);
		
		for(int i=0;i<retry;i++){
			try {
				Invoke invoke=invocation.getInvoke();
				String result=invoke.invoke(invocation);
				return result;
			} catch (Exception e) {
				e.printStackTrace();
				continue;
			}
		}
		throw new RuntimeException("retries" + retry + "全部失败！！！！");
	}

}
